package ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.presentation.controller.util;

import org.icefaces.application.PortableRenderer;
import org.icefaces.application.PushRenderer;
import org.springframework.stereotype.Component;

import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.model.Device;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.service.DeviceChangeListenerFactory;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.devicecontroller.DeviceChangeListener;

@Component
public class DeviceChangeListenerFactoryImp implements
					DeviceChangeListenerFactory {

	private PortableRenderer portableRenderer;

	@Override
	public DeviceChangeListener create(Device dev) {
		DeviceChangeListenerImp ret;
		ret = new DeviceChangeListenerImp();
		ret.setDeviceNumber(dev.getID());
		ret.setPush(getPortableRenderer());
		return ret;
	}

	private PortableRenderer getPortableRenderer() {
		if(portableRenderer == null)
			portableRenderer = PushRenderer.getPortableRenderer();
		return portableRenderer;
	}


}
